package com.ruoyi.system.api.factory;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.api.RemoteOssService;

/**
 * OSS服务降级处理
 * 
 * @author ruoyi
 */
@Component
public class RemoteOssServiceFallbackFactory implements FallbackFactory<RemoteOssService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteOssServiceFallbackFactory.class);

    @Override
    public RemoteOssService create(Throwable throwable)
    {
        log.error("OSS服务调用失败:{}", throwable.getMessage());
        return new RemoteOssService()
        {
            @Override
            public R<Object> uploadFile(MultipartFile file)
            {
                return R.fail("上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> uploadFiles(List<MultipartFile> files)
            {
                return R.fail("批量上传文件失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> deleteFile(String fileUrl)
            {
                return R.fail("删除文件失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> checkFileExists(String fileUrl)
            {
                return R.fail("检查文件存在性失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> getFileUrl(String fileName)
            {
                return R.fail("获取文件URL失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> getSignedUrl(String fileName, long expireTime)
            {
                return R.fail("获取签名URL失败:" + throwable.getMessage());
            }

            @Override
            public R<Object> uploadFilesForDatabase(List<MultipartFile> files, String separator) {
                return R.fail("批量上传文件失败:" + throwable.getMessage());
            }


        };
    }
}